
import { errorMsg } from '../../../utils/tool.js'
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    items: [],  //可选项目列表
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (option) { 
    let self = this;
    let itemsArr = JSON.parse(option.items);
    itemsArr.map((o,i)=>{
      o.isActive = false
    })
    self.setData({
      items: itemsArr
    })
  },
  //选择项目
  onSelect: function (e) { 
    let self = this;
    let { name, id, isSelect } = e.currentTarget.dataset.curitem;
    this.data.items.map((o, i) => {
      
      o.children.map((oo, ii) => {
        if (oo.id == id) {
          oo.isSelect = !isSelect;

        }
      })
    })
    this.setData({
      items: this.data.items,
    })
  },
  onCheckItem:function(e){
    let self = this;
   let id =  e.currentTarget.dataset.id;
   this.data.items.map((o,i)=>{
     if(o.id == id){ 
         o.isActive=!o.isActive 
     } 
   }) 
   this.setData({
     items: this.data.items
   })
  },
  //保存
  onSave: function () {
    let self = this; 
    app.globalData.packageItem = self.data.items;
    wx.navigateBack();
  }
})